Skip to content

feat(copilot): add rtk init --agent copilot support#728

Open
jeziellopes wants to merge 1 commit intortk-ai:developfrom
jeziellopes:feat/copilot-init-agent
Open

feat(copilot): add rtk init --agent copilot support#728
jeziellopes wants to merge 1 commit intortk-ai:developfrom
jeziellopes:feat/copilot-init-agent

Conversation

@jeziellopes
Copy link
Contributor

@jeziellopes jeziellopes commented Mar 19, 2026

Summary

Adds --agent copilot to rtk init, extending the existing AgentTarget enum (cline/windsurf/cursor) with GitHub Copilot support. Closes #823.

Note: This PR predates issue #823 (opened Mar 19, issue opened Mar 25). PR #824 added a basic --copilot flag; this PR is additive — it adds the enum-based --agent copilot alias with the full lifecycle that the other agents have.

What this adds on top of --copilot

Feature --copilot (merged) --agent copilot (this PR)
Enum variant (consistent with --agent cline/windsurf) ❌ standalone bool AgentTarget::Copilot
Idempotency ❌ always re-runs ✅ skips if already set
PATH check ❌ none tool_exists() (cross-platform)
Uninstall ❌ none ✅ strips RTK section, preserves user content
show_config() status ❌ none [ok]/[--] for both .github files

Changes

File Change
src/main.rs AgentTarget::Copilot enum variant; "hook" added to RTK_META_COMMANDS; routing
src/init.rs run_copilot_mode(), uninstall support, show_config() checks, 6 unit tests
.github/hooks/rtk-rewrite.json "rtk hook""rtk hook copilot" (embedded via include_str!)
CHANGELOG.md [Unreleased] entries
# Install (project-scoped, idempotent)
rtk init --agent copilot
# → .github/hooks/rtk-rewrite.json  (PreToolUse hook)
# → .github/copilot-instructions.md (RTK usage rules)

# Uninstall (preserves pre-existing user content)
rtk init --uninstall --agent copilot

# Check status
rtk init --show

Testing

✅ cargo fmt --all
✅ cargo clippy --all-targets (0 errors)
✅ 1129 tests passed (6 new copilot tests)
✅ Manual: install → idempotent re-run → uninstall all verified

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from ed8bc50 to 83e2f8d Compare March 19, 2026 13:36
dgehriger added a commit to dgehriger/rtk that referenced this pull request Mar 20, 2026
Implements PR rtk-ai#728 functionality with improvements:
- rtk init --agent copilot installs both the hook JSON AND lean instructions
- The hook (.github/hooks/rtk-rewrite.json) does the heavy lifting
- Instructions file is minimal (~15 lines) to avoid context pollution
- Uninstall removes instructions but preserves shared hook JSON
- Idempotent: re-running is safe

Unlike upstream PR rtk-ai#728 which only reports hook status, this version
actually installs the hook JSON, making it a one-command setup.

Signed-off-by: Daniel Gehriger <dgehriger@globusmedical.com>
@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from df22aac to e59e5a8 Compare March 20, 2026 14:15
@CLAassistant
Copy link

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from e59e5a8 to d11c613 Compare March 25, 2026 22:59
@jeziellopes
Copy link
Contributor Author

jeziellopes commented Mar 25, 2026

Updated PR to address review gaps and align with issue #823:

Changes in this force-push:

  • Switched from hooks/copilot-rtk-rules.md (new file) to hooks/copilot-rtk-awareness.md (existing file, as specified in feat: rtk init --agent copilot (automated Copilot VS Code + CLI setup) #823)
  • Added PATH verification: warns if rtk binary not in $PATH
  • Added -g flag guard: warns that Copilot setup is always project-scoped
  • Improved idempotent messaging: single "RTK already configured for GitHub Copilot" + early return (matching Cline/Windsurf pattern)
  • Added show_config() status checks: [ok]/[--] for .github/hooks/rtk-rewrite.json and .github/copilot-instructions.md
  • Added rtk init --agent copilot to show_config() Usage block

Additional fixes (self-review, commit 37ebc24):

  • Fixed cross-platform PATH check: replaced which (Unix-only) with crate::utils::tool_exists() — no false-positive warnings on Windows
  • Fixed uninstall data loss: now strips only the RTK section from copilot-instructions.md instead of deleting the whole file; preserves pre-existing user content
  • Added test_uninstall_copilot_preserves_user_content to cover the data-loss scenario
  • All 1120 tests pass

Note on #824: PR #824 uses --copilot flag; this PR uses --agent copilot as specified in #823 (consistent with existing --agent cline/--agent windsurf pattern). Happy to align if you prefer one form.

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 3 times, most recently from 4ff3257 to bd487d6 Compare March 25, 2026 23:24
@aeppling
Copy link
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch 2 times, most recently from ad26930 to fe1cbf3 Compare March 26, 2026 20:17
@jeziellopes
Copy link
Contributor Author

Rebased onto develop after PR #826 (src/ reorganization).

Changes to accommodate the new folder structure:

  • src/init.rssrc/hooks/init.rs (auto-merged cleanly by git)
  • include_str! paths updated: ../hooks/copilot-rtk-awareness.md../../hooks/copilot/rtk-awareness.md, and similarly for the hook JSON
  • crate::utils::tool_existsuse crate::core::utils import added (utils moved to src/core/utils.rs)
  • All routing in src/main.rs already used hooks::init:: prefix — no changes needed there

1129 tests pass, 0 clippy errors.

Adds GitHub Copilot to the AgentTarget enum, following the existing
--agent cline/windsurf/cursor pattern. Closes rtk-ai#823.

- AgentTarget::Copilot in src/main.rs + routing
- run_copilot_mode(): creates .github/hooks/rtk-rewrite.json and
  .github/copilot-instructions.md; idempotent (skips if already set)
- PATH check via crate::utils::tool_exists() (cross-platform, no which)
- uninstall: strips only RTK section, preserves pre-existing user content
- show_config(): [ok]/[--] status for both .github files + usage line
- Fix rtk-rewrite.json: rtk hook -> rtk hook copilot (embedded via
  include_str! so the installed hook is always correct)
- Register hook in RTK_META_COMMANDS so rtk hook copilot routes
  correctly instead of falling through to passthrough mode

Signed-off-by: Jeziel Lopes <jeziel@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jeziellopes jeziellopes force-pushed the feat/copilot-init-agent branch from fe1cbf3 to ca69951 Compare March 26, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants